<?php
namespace Mobile\Controller;
use Think\Controller;
class CommunalController extends Controller{
	const YES=1;//true
	const NO=0;//flase
	private $login_id=0;
	private $login_username='';
	private $login_department='';
	private $login_department_id='';
	private $login_permissions_rule='';
	private $login_permissions_id='';
	private $bool_ip=0;

	//初始方法 designed by:zhangsen 2017-09-20
	function __construct(){
		parent::__construct();
		$this->login_id=$_SESSION['uid'];
		$this->assign('login_id',$this->login_id);
		$this->login_username=$_SESSION['username'];
		$this->assign('login_username',$this->login_username);
		$this->login_department=$_SESSION['department'];
		$this->assign('login_department',$this->login_department);
		$this->login_department_id=$_SESSION['department_id'];
		$this->assign('login_department_id',$this->login_department_id);
		$this->login_permissions_rule=$_SESSION['permissions_rule'];
		$this->assign('login_permissions_rule',$this->login_permissions_rule);
		$this->login_select_id=$_SESSION['select_id'];
		$this->assign('login_select_id',$this->login_select_id);
		$this->login_sw_select_id=$_SESSION['sw_select_id'];
		$this->assign('login_sw_select_id',$this->login_sw_select_id);
		$this->login_manage_id=$_SESSION['manage_id'];
		$this->assign('login_manage_id',$this->login_manage_id);
		$this->login_sw_manage_id=$_SESSION['sw_manage_id'];
		$this->assign('login_sw_manage_id',$this->login_sw_manage_id);
		$this->login_permissions_id=$_SESSION['permissions_id'];
		$this->assign('login_permissions_id',$this->login_permissions_id);
		$this->assign('today',date('Y-m-d'));
		$this->bool_ip=$this->bool_ip();
		$this->assign('bool_ip',$this->bool_ip);
		//操作日志
		if('login'!=ACTION_NAME&&'do_login'!=ACTION_NAME){
			$this->run_log();
		}
	}
		
	//初始方法 designed by:zhangsen 2016-08-11
	public function _initialize(){
		if($_GET['code']){
			$openid=cookie('openid');
			if(empty($openid)){
				cookie('openid',$this->oauth($_GET['code']));
			}
		}
		//查询openid
		if(cookie('openid')){
			$user=$this->get_user(cookie('openid'),2);
			$_SESSION['uid']=$user['id'];
			$_SESSION['username']=$user['username'];
			$_SESSION['permissions_rule']=$user['permissions_rule'];
			$_SESSION['department']=$this->get_department($user['department_id']);
			$_SESSION['department_id']=$user['department_id'];
			$_SESSION['permissions_id']=$user['permissions_id'];
			$_SESSION['center_id']=$user['center_id'];
			$_SESSION['center_type']=$this-$this->get_oa_dep_name($user['center_id']);
		}else{
			$user=$this->get_user($_SESSION['uid']);
		}
		$this->login_id=$user['id'];
		$this->login_username=$user['username'];
		if(empty($this->login_id))
		{
			if('login'!=ACTION_NAME&&'do_login'!=ACTION_NAME&&'personal_data'!=ACTION_NAME&&'back'!=ACTION_NAME)
			{
                $goto = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
                cookie('goto',$goto);
				$login_type=$_REQUEST['center_id'];
				$_SESSION['back_url']=substr($_SERVER["REQUEST_URI"],strpos($_SERVER["REQUEST_URI"],'index.php')+strlen('index.php?s='));;
				$this->redirect("/Mobile/Index/login/login_type/$login_type");
			}
		}
		$this->login_department=$this->get_department($user['department_id']);
		$this->login_department_id=$user['department_id'];
		$this->login_permissions_rule=$user['permissions_rule'];
		$this->login_select_id=explode(',',$user['select_id']);
		$this->login_sw_select_id=explode(',',$user['sw_select_id']);
		$this->login_manage_id=explode(',',$user['manage_id']);
		$this->login_sw_manage_id=explode(',',$user['sw_manage_id']);
		$this->login_permissions_id=$user['permissions_id'];
		$this->login_center_id=$user['center_id'];
		$this->assign('KindEditor_Path',KindEditor_Path);//编辑器
		$permissions_code=explode(',', $this->login_permissions_rule);
		foreach ($permissions_code as $key=> $value) 
		{
			$this->assign('permissions__'.$value,1);
		}
		$this->assign('is_project',$this->get_is_project());//得到我参与的项目权限
		$this->assign('is_project_function',$this->get_is_project_function());//得到授权给我的项目权限
		$this->assign('is_pbc',$this->get_is_pbc());//得到个人pbc权限
		$this->assign('is_task',$this->get_is_task());//得到个人任务管理权限
		header ("Content-Type:text/html; charset=utf-8");
	}
		
	//登录-->判断 designed by:zhangsen 2017-08-14
	function do_login(){
        $goto = isset($_COOKIE['goto']) ? $_COOKIE['goto'] : 'http://' . $_SERVER['HTTP_HOST'] . __APP__ . "/Mobile/Index/index";
		$login_type=$_REQUEST['login_type'];
		$this->assign('username',cookie('username'));
		$username=$_POST['username'];
		$password=$_POST['password'];
		$db_user=M ('db_user'); //获取用户表
		if(!empty($username)){
			$map['regname']=$username;
			$map['mobilephone']=$username;
			$map['email']=$username;
			$map['_logic']='or';
			$where['_complex']=$map;
		}
		$user_ck=$db_user->where($where)->find(); //查询用户是否存在
		if(!empty($user_ck))
		{
			if($user_ck['status']==1)
			{
				$ip=$this->get_ip();
				if($password==$user_ck['password'] || !empty($ip))
				{
					$_SESSION['uid']=$_SESSION['dms_uid']=$user_ck['id'];
					$_SESSION['username']=$_SESSION['dms_username']=$user_ck['username'];
					$user=$this->get_user($_SESSION['uid']);
					$_SESSION['permissions_rule']=$_SESSION['dms_permissions_rule']=$user['permissions_rule'];
					$_SESSION['select_id']=$_SESSION['dms_select_id']=explode(',',$user['select_id']);
					$_SESSION['manage_id']=$_SESSION['dms_manage_id']=explode(',',$user['manage_id']);
					$_SESSION['sw_select_id']=$_SESSION['dms_sw_select_id']=explode(',',$user['sw_select_id']);
					$_SESSION['sw_manage_id']=$_SESSION['dms_sw_manage_id']=explode(',',$user['sw_manage_id']);
					$_SESSION['department']=$_SESSION['dms_department']=$this->get_department($user['department_id']);
					$_SESSION['department_id']=$_SESSION['dms_department_id']=$user['department_id'];
					$_SESSION['permissions_id']=$_SESSION['dms_permissions_id']=$user['permissions_id'];
					$_SESSION['center_id']=$_SESSION['dms_center_id']=$user['center_id'];
					$_SESSION['center_type']=$_SESSION['dms_center_type']=$this-$this->get_oa_dep_name($user['center_id']);
					if(isset($_SESSION['temp']['REQUEST_URI']))
					{
						$url=$_SESSION['temp']['REQUEST_URI'];
						unset($_SESSION['temp']);
					}
					else
					{
						/*
						if($_SESSION['back_url']){
							$url=__APP__.$_SESSION['back_url'];
						}else{
							$url=__APP__."/Mobile/Index/index";
						}
						*/
						$url=__APP__."/Mobile/Index/index";
					}
					//cookie记住用户名
					cookie('username',$_POST['username'],60*60*24*365);
					//绑定微信openid
					if(cookie('openid')){
						$where_u['id']=$user_ck['id'];
						$where_u['openid']=cookie('openid');
						$db_user->save($where_u);
					}
					$this->success('登录成功!',$goto);
				}else{
					$data['status']=self::NO;
					$data['msg']='帐号与密码不匹配,请重新输入';
					echo json_encode($data);die;
				}
			}
			else
			{
				$data['status']=self::NO;
				$data['msg']='该帐号已禁用';
				echo json_encode($data);die;
			}
		}
		else
		{
			$data['status']=self::NO;
			$data['msg']='帐号不存在';
			echo json_encode($data);die;
		}
	}
	
	//查出所有人员 designed by:zhanglijing 2016-12-05
	function get_all_username($status=1,$center_id=NULL,$special=NULL,$date=NULL,$uids=NULL){
		$db_user=M('db_user');
		if(empty($special)){$where['_string']="username!='admin'";}
		if(!empty($center_id)){$where['center_id']=$center_id;}
		if(!empty($uids)){$where['id']=array('in',$uids);}
		$where['status']=$status;
		if(!empty($date))
		{
			$where['add_date']=array('elt',$date);
		}
		$result=$db_user->field('id,username')->where($where)->order('spell')->select();
		return $result;
	}
		
	//查出所有员工号 designed by:zhanglijing 2013-10-29 
	function get_user_number($status=NULL){
		$db_user=M('db_user');
		if(!empty($status)){$where['status']=$status;}
		$where['_string']="user_number is not NULL";
		$result=$db_user->field('id,username,user_number')->where($where)->order('spell')->select();
		return $result;
	}
		
	//查出所有部门 designed by:zhangsen 2017-09-01 
	function get_all_department($uids=NULL){
		$db_user=M('db_user');
		$db_universal_label2=M('db_universal_label2');
		$where['department_id']=array('exp',' is not NULL');
		if(!empty($uids)){$where['id']=array('in',$uids);}
		$where['status']=1;
		$result=$db_user->group('department_id')->where($where)->order('department_id')->select();
		$where_user['status']=1;
		$where_user['id']=array('neq',1);
		foreach($result as $key=>$value)
		{
			//$where_t['id']=$value['department_id'];
			//$third=$db_universal_label2->where($where_t)->find();
			$deps=$this->get_oa_dep_info($value['department_id']);
			$result[$key]['name']=$deps['HPS_DEPT_FULLDESCR'];
			$where_user['department_id']=$value['department_id'];
			if(!empty($uids)){$where_user['id']=array('in',$uids);}
			$result[$key]['user']=$db_user->field('id,username')->where($where_user)->order('spell')->select();
		}
		return $result;
	}
	
	//获取部门名称或id designed by:wangyitian 2017-07-03
	function get_department($department){
		$db_universal_label2=M('db_universal_label2');
		$where_p['id']=$department;
		$result=$db_universal_label2->where($where_p)->find();
		return $result;
	}

	//查出所有权限组；根据权限id查询某一个权限名称，没有id查询所有权限组名称 designed by:zhaoshihao 2016-10-13
	function get_permissions($permissions_id){
		$db_permissions=M('db_permissions');
		if(!empty($permissions_id))
		{
			$where['id']=$permissions_id;
			$result=$db_permissions->field('permissions_name')->where($where)->find();
			return $result['permissions_name'];
		}
		else
		{
			$result=$db_permissions->field('id,permissions_name')->where($where)->order('id asc')->select();
			foreach($result as $k=>$v)
			{
				if($v['permissions_name']=="超级管理员")
				{
					unset($result[$k]);
				}
			}
			return $result;
		}
	}
	
	//检查是否有权限 designed by:stefaniepei 2013-11-26
	function check_permission($num1,$num2,$num3){		
		switch($num2){
			case 1:
				$num2=array('U1','U2','U3');
			break;
			case 2:
				$num2=array('U2','U3');
			break;
			case 3:
				$num2=array('U3');
			break;
			default:
				$num2=array('U1','U2','U3','U0');
			break;
		}
		switch($num3){
			case 1:
				$num3=array('Q1','Q2','Q3');
			break;
			case 2:
				$num3=array('Q2','Q3');
			break;
			case 3:
				$num3=array('Q3');
			break;
			case 4:
				$num3=array('Q0');
			break;
			case 5:
				$num3=array('QQ');
			break;
			default:
				$num3=array('Q1','Q2','Q3','Q0');
			break;
		}
		$bool=0;
		foreach($num2 as $key=>$value) 
		{
			foreach($num3 as $kk=>$vv) 
			{
				if(preg_match("/".$num1.'_'.$value.'_'.$vv."/",$this->login_permissions_rule))
				{
					$bool=1;
					break;	
				}
			}
		}
		if(!$bool)
		{
			$this->error('您没有对应权限!');die;
		}
	}
		
	//登录-->检查当前登录IP designed by:stefaniepei 2013-10-15
	function get_ip(){
		$db_ip=M('db_ip');
		$where['ip']=$_SERVER["REMOTE_ADDR"];
		$ip_result=$db_ip->field('id')->where($where)->find();
		if(!empty($ip_result))
		{
			return $ip_result;
		}
	}
	
	//检查 designed by:zhangsen 2017-02-20
	function bool_ip(){
		$ip=$_SERVER["REMOTE_ADDR"];
		if(!in_array(strtok($ip,'.'),array('10','127','192')))
		{
			return 0;
		}
		return 1;
	}

	//得到用户id designed by:zhanglijing 2014-05-05
	function get_uid($username){
		$db_user=M('db_user');
		$where['username']=$username;
		$uid=$db_user->field('id')->where($where)->find();
		return $uid['id'];
	}
	
	//获取用户username($array=1返回逗号连接的姓名,$array=2返回数组的姓名) designed by:zhaoshihao 2017-06-30
	function get_username($uid,$array=1){
		$db_user=M('db_user');
		$arrays=explode(',',$uid);
		foreach($arrays as $key=>$value){
			$where['id']=$value;
			$user=$db_user->field('username')->where($where)->find();
			$username[]=$user['username'];
		}
		if($array==1){
			$username=join(',',$username);
			return $username;
		}else{
			return $username;
		}
	}
	
	//获取用户详情 designed by:zhanglijing 2016-04-15
	function get_user($uid,$type=1){
		$db_user=M('db_user');
		if($type==1){
			$where['id']=$uid;
		}elseif($type==2){	
			$where['openid']=$uid;
		}
		$result=$db_user->where($where)->find();
		$result['department']=$this->get_department($result['department_id']);
		//权限组
		$db_permissions=M('db_permissions');
		$where_p['id']=array('in',$result['permissions_id']);
		$p_result=$db_permissions->field('permissions_rule,select_id,manage_id,sw_select_id,sw_manage_id')->where($where_p)->select();
		foreach($p_result as $key=>$value){
			$str_p.=$value['permissions_rule'].',';
			if($value['select_id']){$str_s.=$value['select_id'].',';}
			if($value['manage_id']){$str_m.=$value['manage_id'].',';}
			if($value['sw_select_id']){$str_ss.=$value['sw_select_id'].',';}
			if($value['sw_manage_id']){$str_mm.=$value['sw_manage_id'].',';}
		}
		$result['permissions_rule']=rtrim($str_p,',');
		$result['select_id']=rtrim($str_s,',');
		$result['manage_id']=rtrim($str_m,',');
		$result['sw_select_id']=rtrim($str_ss,',');
		$result['sw_manage_id']=rtrim($str_mm,',');
		return $result;
	}
	
	//搜库列表筛选 (参数1:包含全部) designed by:zhaoshihao 2016-11-09
	function library_type_list($classif,$fid=NULL,$sid=NULL,$all=NULL,$fcenter_id=NULL){
		$db_universal_label1=M('db_universal_label1');
		$where['first_name']=array('exp',' is not NULL');
		$where['classif']=$classif;
		if(!empty($fid)){$where['id']=$fid;}
		if(!empty($fcenter_id)){$where['fcenter_id']=$fcenter_id;}
		$result=$db_universal_label1->field('id,first_name,property')->where($where)->order('first_sort')->select();
		$db_universal_label2=M('db_universal_label2');
		$db_universal_label3=M('db_universal_label3');
		$where_type['type_id']=1;
		foreach($result as $k=>$v){
			if(!empty($all)){$where_s['second_name']=array('neq','全部');}
			$where_s['first_id']=$v['id'];
			$result[$k]['second']=$db_universal_label2->field('id,second_name')->where($where_s)->order('second_sort')->select();
			foreach($result[$k]['second'] as $k1=>$v1){
				if(!empty($sid)){
					if(in_array($v1['id'],explode(',',$sid))){
						$where_s['second_id']=$v1['id'];
						$result[$k]['second'][$k1]['third']=$db_universal_label3->field('id,third_name')->where($where_s)->order('third_sort')->select();
					}
				}else{
					$where_s['second_id']=$v1['id'];
					$result[$k]['second'][$k1]['third']=$db_universal_label3->field('id,third_name')->where($where_s)->order('third_sort')->select();
				}
			}
		}
		return $result;
	}
		
	//降维(数组,字段) designed by:zhaoshihao 2016-05-12
	function kg_array_values($array, $field){
		if (empty($array) || !is_array($array))
		{
			return null;
		}
		$result = array();
		foreach ($array as $value)
		{
			if (isset($value[$field]))
			{
				$result[] = $value[$field];
			}
		}
		return $result;
	}

	//得到周几 designed by:zhanglijing 2016-07-18
	function get_day_week($date){
		$db_periodic=M('db_periodic');
		$where['db_date']=$date;
		$result=$db_periodic->field('day_of_week')->where($where)->find();
		return $result['day_of_week'];
	}

	//年/月/周相关数据 designed by:zhanglijing 2015-09-18
	function get_year_month_week($type=1,$year_now,$week_now){
		if($type==1)
		{//大去年,去年,今年,明年的数组
			$year[]=$this->get_date("Y","-2 year");
			$year[]=$this->get_date("Y","-1 year");
			$year[]=date('Y');
			$year[]=$this->get_date("Y","+1 year");
			return $year;
		}
		elseif($type==2)
		{//12个月,01,02,03,04,05,06,07,08,09,10,11,12的数组
			$month[]='01';
			$month[]='02';
			$month[]='03';
			$month[]='04';
			$month[]='05';
			$month[]='06';
			$month[]='07';
			$month[]='08';
			$month[]='09';
			$month[]='10';
			$month[]='11';
			$month[]='12';
			return $month;
		}
		elseif($type==3)
		{//12个月,1,2,3,4,5,6,7,8,9,10,11,12的数组
			$month[]='1';
			$month[]='2';
			$month[]='3';
			$month[]='4';
			$month[]='5';
			$month[]='6';
			$month[]='7';
			$month[]='8';
			$month[]='9';
			$month[]='10';
			$month[]='11';
			$month[]='12';
			return $month;
		}
		elseif($type==4)
		{//所有周的数组
			$big_week=$this->get_date("W",NULL,$year_now.'-12-31');
			if($big_week==1){$big_week=$this->get_date("W",NULL,$year_now.'-12-30');}
			if($big_week==1){$big_week=$this->get_date("W",NULL,$year_now.'-12-29');}
			if($big_week==1){$big_week=$this->get_date("W",NULL,$year_now.'-12-28');}
			if($big_week==1){$big_week=$this->get_date("W",NULL,$year_now.'-12-27');}
			if($big_week==1){$big_week=$this->get_date("W",NULL,$year_now.'-12-26');}
			if($big_week==1){$big_week=$this->get_date("W",NULL,$year_now.'-12-25');}
			if($big_week==1){$big_week=$this->get_date("W",NULL,$year_now.'-12-24');}
			for($i=1;$i<=$big_week;$i++)
			{
				$week[]=$i;
			}
			return $week;
		}
		elseif($type==5)
		{//最大周数
			$big_week=$this->get_date("W",NULL,$year_now.'-12-31');
			if($big_week==1){$big_week=$this->get_date("W",NULL,$year_now.'-12-30');}
			if($big_week==1){$big_week=$this->get_date("W",NULL,$year_now.'-12-29');}
			if($big_week==1){$big_week=$this->get_date("W",NULL,$year_now.'-12-28');}
			if($big_week==1){$big_week=$this->get_date("W",NULL,$year_now.'-12-27');}
			if($big_week==1){$big_week=$this->get_date("W",NULL,$year_now.'-12-26');}
			if($big_week==1){$big_week=$this->get_date("W",NULL,$year_now.'-12-25');}
			if($big_week==1){$big_week=$this->get_date("W",NULL,$year_now.'-12-24');}
			return $big_week;
		}
		elseif($type==6)
		{//指定年和周的日期数组
			$time=new \DateTime();
			$time->setISODate($year_now,$week_now,1);
			$result[]=$time->format('Y-m-d');
			$time->setISODate($year_now,$week_now,2);
			$result[]=$time->format('Y-m-d');
			$time->setISODate($year_now,$week_now,3);
			$result[]=$time->format('Y-m-d');
			$time->setISODate($year_now,$week_now,4);
			$result[]=$time->format('Y-m-d');
			$time->setISODate($year_now,$week_now,5);
			$result[]=$time->format('Y-m-d');
			$time->setISODate($year_now,$week_now,6);
			$result[]=$time->format('Y-m-d');
			$time->setISODate($year_now,$week_now,7);
			$result[]=$time->format('Y-m-d');
			return $result;
		}
		elseif($type==7)
		{//2011年到明年的年份
			for($i=2011;$i<=$this->get_date("Y","+1 year");$i++){
				$year[]=$i;
			}
			return $year;
		}elseif ($type==8){
            //大去年,去年,今年,明年的数组
            $year[] = $this->get_date("Y", "-1 year");
            $year[] = date('Y');
            $year[] = $this->get_date("Y", "+1 year");
            $year[] = $this->get_date("Y", "+2 year");
            return $year;
        }
	}
	
	
	//获得节假日 designed by:zhanglijing 2015-09-18
	function get_holiday($year,$name){
		$db_holiday=M('db_holiday');
		$where['year']=$year;
		$where['name']=$name;
		$result=$db_holiday->where($where)->find();
		return $result;
	}
	//获得所有节假日 designed by:zhanglijing 2015-09-18
	function get_holiday_all($year){
		$db_holiday=M('db_holiday');
		$where['year']=$year;
		$result=$db_holiday->where($where)->order('week')->select();
		return $result;
	}
	
	//得到日期加减操作(参数:$return返回日期类型,$string加减逻辑字符串(例如："+1 years","+1 month","+1 day"),$date指定日期值)designed by:zhangsen 2017-04-28
	/*
	用法:
	$this->get_date("Y-m-d","+1 day");当前日期加一天
	$this->get_date("Y-m-d","+1 month",$date);指定日期下一月
	$this->get_date("Y-m","+1 years",$date);指定日期下一年的年月
	$this->get_date("Y-m-t",NULL,$date);指定日期的月底
	$this->get_date("m","+1 month",$date);指定日期下一个月的月份(获取月份时候，日期必填。不然个别日期会有bug存在)
	等等，根据需求自己获取。代码里面strtotime获取日期的地方都会变成公共方法调用。
	*/
	function get_date($return,$string,$date){
		if(empty($return)){
			$return="Y-m-d";
		}
		if(empty($string)){
			$string="now";
		}
		if(empty($date)){
			$date = time();
		}else{
			$date = strtotime(date($date));
		}
		if(preg_match("/month/",$string))
		{
			$first_day_of_month = date('Y-m',$date).'-01';
			$str_date = strtotime($first_day_of_month);
		}
		if(preg_match("/month/",$string))
		{
			$l_date=date("Y-m-d",strtotime($string,$str_date));
			$day=substr(date("Y-m-d",$date),8,2);
			if(substr($l_date,0,7).'-'.date('t',strtotime(substr($l_date,0,7)))<substr($l_date,0,7).'-'.$day){
				$l_date=substr($l_date,0,7).'-'.date('t',strtotime(substr($l_date,0,7)));
			}else{
				$l_date=substr($l_date,0,7).'-'.$day;
			}
			$l_date=date($return,strtotime($l_date));
			return $l_date;
		}else{
			return date($return,strtotime($string,$date));
		}
	}
	
	//汉字字符串截取 designed by:wangyitian 2017-08-03
	function msubstr($str, $start=0, $length, $charset="utf-8", $suffix=true)
	{
		if(function_exists("mb_substr"))
		{
			if($suffix)
			{
				return mb_substr($str, $start, $length, $charset)."...";
			}
			else
			{
				return mb_substr($str, $start, $length, $charset);
			}
		}
		elseif(function_exists('iconv_substr'))
		{
			if($suffix)
			{
				return iconv_substr($str,$start,$length,$charset)."...";
			}
			else
			{
				return iconv_substr($str,$start,$length,$charset);
			}
		}
		$re['utf-8']   = "/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xff][\x80-\xbf]{3}/";
		$re['gb2312'] = "/[\x01-\x7f]|[\xb0-\xf7][\xa0-\xfe]/";
		$re['gbk']    = "/[\x01-\x7f]|[\x81-\xfe][\x40-\xfe]/";
		$re['big5']   = "/[\x01-\x7f]|[\x81-\xfe]([\x40-\x7e]|\xa1-\xfe])/";
		preg_match_all($re[$charset], $str, $match);
		$slice = join("",array_slice($match[0], $start, $length));
		if($suffix)
		{ 
			return $slice."...";
		}
		else
		{
			return $slice;
		}
	}

	//获取公共类别表数据(参数说明:$type/$name1/$name2/$name3/$name4/$id:表字段,$ftype:查询使用select/find返回一维/二维数组,$stype:逗号分割数据返回数组) designed by:wsangyitian 2017-02-16
	function get_db_universal_type($type=NULL,$ftype=NULL,$stype=NULL,$main=NULL,$name1=NULL,$name2=NULL,$name3=NULL,$name4=NULL,$id=NULL){
		$db_universal_type=M('db_universal_type');
		if(!empty($type)){$where['type']=$type;}
		if(!empty($name1)){$where['name1']=$name1;}
		if(!empty($name2)){$where['name2']=$name2;}
		if(!empty($name3)){$where['name3']=$name3;}
		if(!empty($name4)){$where['name4']=$name4;}
		if(!empty($id)){$where['id']=$id;}
		if(!empty($ftype)){
			$result=$db_universal_type->where($where)->find();
		}else{
			$result=$db_universal_type->where($where)->order('id')->select();
		}
		if(!empty($stype)){
			$name_arr1=explode(',',$result['name1']);
			if(!empty($result['name2'])){$name_arr2=explode(',',$result['name2']);}
			unset($result);
			foreach($name_arr1 as $key=>$value){
				$result[$key]['name1']=$value;
			}
			if(!empty($name_arr2))
			{
				foreach($name_arr2 as $key=>$value){
					$result[$key]['name2']=$value;
				}
			}
		}
		if(!empty($main)){
			foreach($result as $key=>$value){
				if($value['name2']==1000){
					unset($result[$key]);
				}
			}
		}
		return $result;
	}
	
	//获取标签表数据 designed by:zhangsen 2017-09-16
	function get_db_universal_label($type=NULL,$id=NULL){
		$db_universal_label1=M('db_universal_label1');
		$db_universal_label2=M('db_universal_label2');
		$db_universal_label3=M('db_universal_label3');
		$where['id']=$id;
		if($type==1){
			$result_arr=$db_universal_label1->where($where)->find();
			$result=$result_arr['first_name'];
		}elseif($type==2){
			$result_arr=$db_universal_label2->where($where)->find();
			$result=$result_arr['second_name'];
		}elseif($type==3){
			$result_arr=$db_universal_label3->where($where)->find();
			$result=$result_arr['third_name'];
		}
		return $result;
	}
	
	//获取项目信息 designed by:zhangsen 2017-09-15
	function get_project($pid){
		$db_project=M('db_project');
		$where['id']=$pid;
		$project=$db_project->where($where)->find();
		return $project;
	}
	
	//获取项目信息 new add by chenyan 2018-09-18
	function get_project_new($pid){
		$db_project=M('db_crm_project');
		$where['project_id']=$pid;
		$project=$db_project->where($where)->find();
		return $project;
	}
	/*
		将config中的常量转换成循环可读形式
		$list 常量结果集合
		add by chenyan 2018-09-21
	*/
	public function get_constant($list){
		$result = array();
		foreach($list as $k=>$l){
			$result[$k]['id']=$k;
			$result[$k]['name']=$l;
		}
		return $result;
	}
	/* add by chenyan 09-21*/
	function get_work_type($wt){
		$str = str_replace("1","工作建议书 ",$wt);
		$str = str_replace("2","计划书沟通 ",$str);
		$str = str_replace("3","合同沟通 ",$str);
		$str = str_replace("4","前期沟通 ",$str);
		return $str;
	}
	
	
	//得到项目启动表 designed by:zhanglijing 2013-11-14
	function get_project_bg($pid,$status){
		$db_project_bg=M('db_project_bg');
		$where['pid']=$pid;
		if($status){$where['status']=$status;}
		$project_bg=$db_project_bg->where($where)->find();
		return $project_bg;
	}
		
	//得到省市信息(type=1:得到省市;type=2:省市id转名字;type=3:省市名字转id,$bool:返回类型)designed by:wangyitian 2017-05-11
	function get_province_city($region,$type=1,$bool=NULL){
		$db_province_city=M('db_province_city');
		if($type==1){
			if($region==NULL){$where['reid']=0;}else{$where['reid']=$region;}
			$result=$db_province_city->where($where)->select();
		}elseif($type==2){
			if($region!=NULL){$where['id']=$region;}
			$list=$db_province_city->where($where)->find();
			$result=$list['name'];
		}elseif($type==3){
			if($region!=NULL){$where['name']=$region;}
			$list=$db_province_city->where($where)->find();
			$result=$list['id'];
		}
		if($bool==NULL){
			return $result;
		}else{
			echo json_encode($result);
		}
	}
	
	//操作日志
	function run_log(){
		$db_run_log=M('db_run_log');
        $data['uid']=$this->login_id;
        $data['username']=$this->login_username;
		$data['url']=substr($_SERVER["REQUEST_URI"],strpos($_SERVER["REQUEST_URI"],'index.php')+strlen('index.php?s='));
		$data['ip']=$_SERVER["REMOTE_ADDR"];
        $data['add_date']=date("Y-m-d H:i:s");
        $db_run_log->add($data);
	}
			
	//我参与的项目权限 designed by:zhangsen 2017-09-29
	function get_is_project(){
		$db_project=M('db_project'); 
		$where['_string']="(manager_uid=".$this->login_id.") or (director_uid=".$this->login_id.")";
		$count=$db_project->field('db_project.id')->where($where)->count();
		if($count>0){
			return 1;
		}
	}

	//项目功能权限 designed by:zhangsen 2017-10-24
	function get_is_project_function(){
		$db_project_function=M('db_project_function'); 
		$where['uid']=$this->login_id;
		$where['start_date']=array('elt',date("Y-m-d"));
		$where['end_date']=array('egt',date("Y-m-d"));
		$count=$db_project_function->where($where)->count();
		if($count>0){
			return 1;
		}
	}
	
	//PBC个人权限 designed by:zhangsen 2018-03-19
	function get_is_pbc(){
		$db_jixiao_pbc_user=M('db_jixiao_pbc_user'); 
		$where['u_id']=$this->login_id;
		$where['status']=1;
		$count=$db_jixiao_pbc_user->where($where)->count();
		if($count>0){
			return 1;
		}
	}

	//个人任务管理权限 designed by:zhangsen 2018-03-26
	function get_is_task(){
		$db_task=M('db_task');
		$db_task_detail=M('db_task_detail');
		$where_d['uid']=$this->login_id;
		$result_d=$db_task_detail->field('mid')->where($where_d)->select();
		foreach($result_d as $key=>$value){
			$mid_str.=$value['mid'].',';
		}
		if($mid_str){
			$where['_string']="db_task.id in (".rtrim($mid_str,',').") or db_task.head_uid='".$this->login_id."' or db_audit_main.add_uid='".$this->login_id."'";
		}
		else{
			$where['_string']=" db_task.head_uid='".$this->login_id."' or db_audit_main.add_uid='".$this->login_id."'";
		}
		$count=$db_task->join('db_audit_main on db_task.id=db_audit_main.audit_id')->where($where)->count();
		if($count>0){
			return 1;
		}
	}
	
	//获取微信openid designed by:zhangsen 2017-11-03
	function oauth($code){
		$weixin =  file_get_contents("https://api.weixin.qq.com/sns/oauth2/access_token?appid=wxa9104bb1d0267056&secret=1e77aa81ba98a0f0fd8699dc41d1ad87&code=".$code."&grant_type=authorization_code");//通过code换取网页授权access_token
		$jsondecode = json_decode($weixin); //对JSON格式的字符串进行编码
		$array = get_object_vars($jsondecode);//转换成数组
		return $array['openid'];
	}
	
	//审核流程-审核对应分组 designed by:zhaoshihao 2016-07-27
	function audit_user($type,$audit_type=NULL,$audit_name=NULL){
		$db_universal_audit=M('db_universal_audit');
		$where['type']=$type;
		if(!empty($audit_type)){$where['audit_type']=$audit_type;}
		if(!empty($audit_name)){$where['audit_name']=$audit_name;}
		$result=$db_universal_audit->where($where)->order('audit_sort')->select();
		return $result;
	}
	
	//审核流程-下一步审核判断 designed by:zhangsen 2016-08-12
	function audit_type_next_person($type,$audit_type,$status,$sort){
		$db_universal_audit=M('db_universal_audit');
		$where['type']=$type;
		$where['audit_type']=$audit_type;
		$where['audit_uid']=array('exp','IS NOT NULL');
		if($sort=='egt'){
			$where['audit_sort']=array('egt',$status);
			$result=$db_universal_audit->where($where)->order('audit_sort asc')->find();
		}
		elseif($sort=='lt'){
			$where['audit_sort']=array('lt',$status);
			$result=$db_universal_audit->where($where)->order('audit_sort desc')->find();
		}
		else{
			$where['audit_sort']=$status;
			$result=$db_universal_audit->where($where)->order('audit_sort')->find();
		}
		return $result;
	}
	
	function get_oa_dep_info($dept_id){
		$db_department=M('db_department');
		$where['DEPTID']=$dept_id;
		$where['EFF_STATUS']='A';
		$result=$db_department->where($where)->find();
		return $result;
	}
	
	function get_oa_dep_list(){
		$db_department=M('db_department');
		$where['PART_DEPTID_CHN']=130001;
		$where['EFF_STATUS']='A';
		$result=$db_department->field('DEPTID as id,DEPT_DESCR as first_name')->where($where)->order('SORT')->select();
		return $result;
	}
	
	function get_oa_dep_name($id){
		$db_department=M('db_department');
		$where['DEPTID']=$id;
		$result=$db_department->where($where)->find();
		return $result['DEPT_DESCR'];
	}
	
	//用户列表-->审核/审批关系 designed by:zhangsen 2018-05-08
	function user_list_ajax_relationship($type,$uid,$status=NULL,$leader_uid=NULL){
		//用户详情
		$user=$this->get_user($uid);
		$db_relationship=M('db_relationship');
		if($type==1)
		{
			//查出此用户的审核/审批人
			$where_relationship['_string']='find_in_set("'.$uid.'",person_uid)';
			$relationship=$db_relationship->where($where_relationship)->select();
			if(!empty($relationship))
			{
				foreach($relationship as $key=>$value)
				{
					if($value['status']==1)
					{
						$result['audit_uid']=$value['leader_uid'];
						$result['audit_user']=$value['leader_name'];
					}
					else
					{
						$result['approval_uid']=$value['leader_uid'];
						$result['approval_user']=$value['leader_name'];
					}
				}
				return $result;
			}
		}
		elseif($type==2)
		{
			//添加用户的审核/审批人
			$where_relationship['leader_uid']=$leader_uid;
			$where_relationship['status']=$status;
			$relationship=$db_relationship->where($where_relationship)->find();
			if(!empty($relationship))
			{
				$where_save['id']=$relationship['id'];
				$where_save['person_uid']=$relationship['person_uid'].','.$uid;
				$where_save['person_name']=$relationship['person_name'].','.$user['username'];
				$db_relationship->save($where_save);
			}
			else
			{
				$where_add['leader_uid']=$leader_uid;
				$leader_name=$this->get_user($leader_uid);
				$where_add['leader_name']=$leader_name['username'];
				$where_add['person_uid']=$uid;
				$where_add['person_name']=$user['username'];
				$where_add['status']=$status;
				$db_relationship->add($where_add);
			}
		}
		elseif($type==3)
		{
			//删除用户的审核/审批人
			$where_relationship['leader_uid']=$leader_uid;
			$where_relationship['status']=$status;
			$relationship=$db_relationship->where($where_relationship)->find();
			$person_uid=explode(',',$relationship['person_uid']);
			if(count($person_uid)==1)
			{
				$where_delete['id']=$relationship['id'];
				$db_relationship->where($where_delete)->delete();
			}
			else
			{
				foreach($person_uid as $key=>$value)
				{
					if($value!=$uid)
					{
						$person_uid_array[]=$value;
					}
				}
				$person_name=explode(',',$relationship['person_name']);
				foreach($person_name as $key=>$value)
				{
					if($value!=$user['username'])
					{
						$person_name_array[]=$value;
					}
				}
				$where_save['id']=$relationship['id'];
				$where_save['person_uid']=implode(',',$person_uid_array);
				$where_save['person_name']=implode(',',$person_name_array);
				$db_relationship->save($where_save);
			}
		}
		elseif($type==4)
		{
			//查询此用户需要审核/审批的人员
			$where_relationship['leader_uid']=$uid;
			$where_relationship['status']=$status;
			$relationship=$db_relationship->field('person_uid')->where($where_relationship)->find();
			return $relationship['person_uid'];
		}
	}
	
	//审核流程-下一步审核判断 designed by:zhangsen 2016-08-12
	function audit_type_next($type,$audit_type,$status,$sort){
		$db_universal_audit=M('db_universal_audit');
		$where['type']=$type;
		if(!empty($audit_type)){$where['audit_type']=$audit_type;}
		if($sort=='gt'){
			$where['audit_sort']=array('gt',$status);
			$order='audit_sort';
		}
		elseif($sort=='lt'){
			$where['audit_sort']=array('lt',$status);
			$order='audit_sort desc';
		}
		else{
			$where['audit_sort']=$status;
		}
		$where['audit_uid']=array('exp','IS NOT NULL');
		$result=$db_universal_audit->where($where)->order($order)->find();
		return $result;
	}
	
	//curl_post发送请求 designed by:zhangsen 2018-05-17
	function curl_post($url,$data=array()){
		$ch=curl_init();
		curl_setopt($ch,CURLOPT_URL, $url);
		curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
		curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,FALSE);
		curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,FALSE);
		//POST数据
		curl_setopt($ch, CURLOPT_POST,1);
		//把post的变量加上
		curl_setopt($ch,CURLOPT_POSTFIELDS,$data);
		$output=curl_exec($ch);
		curl_close($ch);
		return $output;
	}
	
	//微信发送审核提醒 designed by:zhangsen 2018-05-17
	function send_audit_notice($openid,$url,$first,$keyword1,$keyword2,$keyword3,$keyword4,$remark){
		$ip=$this->get_ip();
		if(empty($ip) || $_SERVER['SERVER_ADDR']=='192.168.0.7')
		{
			//获取access_token
			if($_COOKIE['access_token']){
				$access_token2=$_COOKIE['access_token'];
			}else{
				$json_token=$this->curl_post("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wxa9104bb1d0267056&secret=1e77aa81ba98a0f0fd8699dc41d1ad87");
				$access_token1=json_decode($json_token,true);
				$access_token2=$access_token1['access_token'];
				setcookie('access_token',$access_token2,7200);
			}
			//模板消息
			$template=array(
				'touser'=>$openid,//用户openid
				'template_id'=>"hNulYpuefkRz4A_ODtr14cxMkHGZ5_2r8sN0gzqQMco",//在公众号下配置的模板id
				'url'=>$url,//点击模板消息会跳转的链接
				'topcolor'=>"#7B68EE",
				'data'=>array(
					'first'=>array('value'=>urlencode($first),'color'=>"#FF0000"),
					'keyword1'=>array('value'=>urlencode($keyword1),'color'=>'#FF0000'),//keyword需要与配置的模板消息对应
					'keyword2'=>array('value'=>urlencode($keyword2),'color'=>'#FF0000'),
					'keyword3'=>array('value'=>urlencode($keyword3),'color'=>'#FF0000'),
					'keyword4'=>array('value'=>urlencode($keyword4),'color'=>'#FF0000'),
					'remark'=>array('value'=>urlencode($remark)),
				)
			);
			$json_template=json_encode($template);
			$url="https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=".$access_token2;
			$res=$this->curl_post($url,urldecode($json_template));
		}
	}
	
	//微信发送任务提醒 designed by:zhangsen 2018-05-17
	function send_task_notice($openid,$url,$first,$keyword1,$keyword2,$keyword3,$keyword4,$remark){
		$ip=$this->get_ip();
		if(empty($ip) || $_SERVER['SERVER_ADDR']=='192.168.0.7')
		{
			//获取access_token
			if($_COOKIE['access_token']){
				$access_token2=$_COOKIE['access_token'];
			}else{
				$json_token=$this->curl_post("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wxa9104bb1d0267056&secret=1e77aa81ba98a0f0fd8699dc41d1ad87");
				$access_token1=json_decode($json_token,true);
				$access_token2=$access_token1['access_token'];
				setcookie('access_token',$access_token2,7200);
			}
			//模板消息
			$template=array(
				'touser'=>$openid,//用户openid
				'template_id'=>"rSoS-X_sTdHgHeYVgTvVk9idy94NIBgbnpX20fnQEFc",//在公众号下配置的模板id
				'url'=>$url,//点击模板消息会跳转的链接
				'topcolor'=>"#7B68EE",
				'data'=>array(
					'first'=>array('value'=>urlencode($first),'color'=>"#FF0000"),
					'keyword1'=>array('value'=>urlencode($keyword1),'color'=>'#FF0000'),//keyword需要与配置的模板消息对应
					'keyword2'=>array('value'=>urlencode($keyword2),'color'=>'#FF0000'),
					'keyword3'=>array('value'=>urlencode($keyword3),'color'=>'#FF0000'),
					'remark'=>array('value'=>urlencode($remark)),
				)
			);
			$json_template=json_encode($template);
			$url="https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=".$access_token2;
			$res=$this->curl_post($url,urldecode($json_template));
		}
	}
	
	function audit_status_judge($arrive_status){
		if($arrive_status==-1){
			$up_where['post_uid']=NULL;
			$up_where['post_date']=NULL;
			$up_where['post_user']=NULL;
			//array('post_uid'=>NULL,'post_date'=>NULL);
		}else{
			
			for($i=1;$i<=$arrive_status;$i++)
			{
				if($i==$arrive_status){
					switch($arrive_status){
						case $i:
							$up_where['audit'.$i.'_uid']=NULL;
							$up_where['audit'.$i.'_user']=NULL;
							$up_where['audit'.$i.'_date']=NULL;
							$up_where['audit'.$i.'_message']=NULL;
							//$up_where='(audit'.$i.'_uid=NULL and audit'.$i.'_date=NULL and audit'.$i.'_message=NULL)';
						break;
					}
				}
			}
		}
		return $up_where;
	}
	
	function audit_status_judge_all($arrive_status,$dh_status){
		if($arrive_status==-1){
			$up_where['post_uid']=NULL;
			$up_where['post_date']=NULL;
			$up_where['post_user']=NULL;
			for($i=1;$i<=$dh_status;$i++)
			{
				$up_where['audit'.$i.'_uid']=NULL;
				$up_where['audit'.$i.'_user']=NULL;
				$up_where['audit'.$i.'_date']=NULL;
				$up_where['audit'.$i.'_message']=NULL;
			}
		}else{
			for($i=$arrive_status;$i<=$dh_status;$i++)
			{
				$up_where['audit'.$i.'_uid']=NULL;
				$up_where['audit'.$i.'_user']=NULL;
				$up_where['audit'.$i.'_date']=NULL;
				$up_where['audit'.$i.'_message']=NULL;
			}
		}
		
		return $up_where;
	}

    //数组重新排序 multi_array_sort(数组，键名，排序方式) designed by:stefaniepei 2013-10-15
    function multi_array_sort($multi_array,$sort_key,$sort=SORT_DESC){
        if(is_array($multi_array)){
            foreach ($multi_array as $row_array){
                if(is_array($row_array)){
                    $key_array[]=$row_array[$sort_key];
                }else{
                    return false;
                }
            }
        }else{
            return false;
        }
        array_multisort($key_array,$sort,$multi_array);
        return $multi_array;
    }

    //获取当前日期的上一周期或者下一周期(参数3:1上一周期/2下一周期,参数4:周期/整年/整月/整周) designed by:zhanglijing 2017-02-10
    function start_end_cycle_adjust($start_end,$time,$type,$way){
        if($way==1)
        {
            if($type==1)
            {
                if($start_end==1)
                {
                    $date=$this->get_date("Y-m-26","-1 month",$time);
                }
                else
                {
                    $date=$this->get_date("Y-m-25",NULL,$time);
                }
            }
            elseif($type==2)
            {
                if($start_end==1)
                {
                    $date=$this->get_date("Y-m-26","+1 month",$time);
                }
                else
                {
                    $date=$this->get_date("Y-m-25","+2 month",$time);
                }
            }
        }
        elseif($way==2)
        {
            if($type==1)
            {
                if($start_end==1)
                {
                    $date=$this->get_date("Y-01-01","-1 year",$time);
                }
                else
                {
                    $date=$this->get_date("Y-12-31","-1 year",$time);
                }
            }
            elseif($type==2)
            {
                if($start_end==1)
                {
                    $date=$this->get_date("Y-01-01","+1 year",$time);
                }
                else
                {
                    $date=$this->get_date("Y-12-31","+1 year",$time);
                }
            }
        }
        elseif($way==3)
        {
            if($type==1)
            {
                if($start_end==1)
                {
                    $date=$this->get_date("Y-m","-1 month",$time);
                }
                else
                {
                    $date=$this->get_date("Y-m","-1 month",$time);
                }
            }
            elseif($type==2)
            {
                if($start_end==1)
                {
                    $date=$this->get_date("Y-m","+1 month",$time);
                }
                else
                {
                    $date=$this->get_date("Y-m","+1 month",$time);
                }
            }
        }
        elseif($way==4)
        {
            if($type==1)
            {
                $date=$this->get_date("Y-m-d","-7 day",$time);
            }
            elseif($type==2)
            {
                $date=$this->get_date("Y-m-d","+7 day",$time);
            }
        }
        return $date;
    }
	/*
		获取项目对应的联系人
		参数：linkman 联系人编号
		返回 结果集联系人的信息
		add by chenyan 2018-09-11
	*/
	public function getContactByProjectLinkman($linkman){
		$db_crm_contact = M('db_crm_contact');
		$where["_string"]="contact_id in (".$linkman.")";
		$re = $db_crm_contact->field("contact_id,username,mobilephone")->where($where)->select();
		return $re;
	}
	/*
		统计时间，计算当前时间在1年中的第几周，以及本周的开始日期和结束日期
		参数 $now 格式：date("Y-m-d")
		返回值：当前年份，当日在整年中的第几周，本周的开始日期和结束日期
		add by chenyan	2019-09-13
	*/
	public function getNowTimeInfo($now){
		$str = array();
		//$first =1 表示每周星期一为开始日期 0表示每周日为开始日期
		$str['year']=date('Y',strtotime($now));
		$first=1;
		//当日在整年中的第几周
		$str['week']=date('W',strtotime($now));
		//获取当前周的第几天 周日是 0 周一到周六是 1 - 6
		$w=date('w',strtotime($now));
		//获取本周开始日期，如果$w是0，则表示周日，减去 6 天
		$week_start=date('Y-m-d',strtotime("$now -".($w ? $w - $first : 6).' days'));
		$str['week_start']=$week_start;
		//本周结束日期
		$week_end=date('Y-m-d',strtotime("$week_start +6 days"));
		$str['week_end']=$week_end;
		return $str;
	}
	/*
		将提交的空值过滤，需要提交的值和数据库值一致
		参数: $result 需要洗的结果集合
			  $arr 返回值存放的数组
		返回：有值的数组
		add by chenyan 2018-09-06
	*/
	public function unset_null($result,$arr){
		foreach($result as $k=>$r){  
			if(!$r){
				unset($result[$k]);  
			}else{
				$arr[$k]=$r;
			}  
		}
		return $arr;
	}
	/*
		更新project表中的联系人
		add by chenyan	2019-09-18
	*/
	public function update_project_contact($pid,$cid){
		$db_crm_project=M('db_crm_project');
        $result_old = $db_crm_project->where("project_id=$pid")->find();
		$data['project_id']=$pid;
		if($result_old==""){
			$data['other_linkman'] = $cid;
		}else{
			$data['other_linkman'] = $result_old['other_linkman'].",".$cid;
		}
		$db_crm_project->save($data);
	}
	/*
		更新项目流程
		参数：pid 		项目id
			  status	项目状态
			  remark	备注
			  au		添加人id
			  aname		添加人姓名
			  adate		添加时间
		add by chenyan	2019-09-12
	*/
	public function update_project_flow($pid,$status,$remark,$au,$aname,$adate){
		$db_crm_project_flow=M('db_crm_project_flow');
		$where['project_id']=$pid;
		$where['status']=$status;
		$where['remark']=$remark;
		$where['add_uid']=$au;
		$where['add_user']=$aname;
		$where['add_date']=$adate;
		$db_crm_project_flow->add($where);
	}
	
}
?>